<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户注册界面</title>
</head>
<script type="text/javascript" src="../../js/jquery-3.6.0.min.js"></script>
<style>
    body{
        background-image: url(../../img/loginBac.jpg);
        width: 100%;
        height: 100%;
    }
</style>
<div th:include="common/style"></div>
<body>
<form class="readerRegister">
    <input type="hidden" name="uRoleid" value="1">
    <table>
        <tr>
            <td>
                <h2>用户注册</h2>
            </td>
            <td style="text-align: right; font-size: small;">
                已有账号？<a th:href="@{toLoginReader}">直接登录</a>
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>手机号</td>
            <td>
                <input type="tel" name="uTel" id="utel">
            </td>

        </tr>
        <tr>
            <td style="text-align: right">用户名</td>
            <td>
            <input type="text" name="uName"><br>
                <span id="sp1"></span>
            </td>
        </tr>

        <tr>
            <td style="text-align: right"><font color="red">*</font>设置密码</td>
            <td>
            <input type="password" id="upwd1">
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>确认密码</td>
            <td>
            <input type="password" name="uPwd" id="upwd2" onblur="checkPwd()">
            </td>
        </tr>
    </table>
    <p class="tip" style="text-align: right">
        <input type="checkbox" id="read">
        <span>
        <input type="checkbox" id="read">&nbsp;&nbsp;我已阅读并同意
        <a th:href="@{agreement}" target="_blank">《用户协议》</a>
        <a th:href="@{agreement}" target="_blank">《隐私协议》</a>
        </span>
    </p>
    <p style="text-align: center">
        <input type="button" value="确认注册" onclick="checkAll()" class="btn-primary">
    </p>
</form>
</body>
<script>
    //手机号校验
    function checkDel(){
        var tel = /^[0-9]{11}$/;
        if(tel.test($("#utel").val())){
            return true;
        }else {
            return false;
        }
    }

    function checkPwd(){
        var pwd1 = $("#upwd1").val();
        var pwd2 = $("#upwd2").val();
        if (pwd1 == pwd2){
            return true;
        }else {
            alert("两次密码输入不一致，请检查，重新输入")
        }
    }

    function checkAll(){
        var f1 = checkDel();
        var f2 = checkPwd();
        if ($("#read:checked").val()){
            if (f1 && f2){
                $.ajax({
                    url:"addUser",
                    type:"post",
                    dataType:"text",
                    data:$("form").serialize(),
                    success:function (data){
                        if (data == 1){
                            $("#sp1").html("<font color='red' size='2'>!该用户名已被注册，请更换</font>")
                        }
                        if (data == "success"){
                            alert("注册成功");
                            location.href = "toLoginReader";
                        }
                    },error:function (){
                        alert("注册失败");
                    }
                })
            }else {
                alert("输入信息有不合法内容，请检查")
                return false;
            }
        }else {
            alert("请勾选权益须知");
            return false;
        }
    }

</script>
</html>